﻿(function () {
    var CollisionDetector = function () {
    };
    CollisionDetector.prototype = {
        getCollisions: function (fallingObject, earth) {
            var collisions = {};
            for (var i = 0; i < fallingObject.getBody.length; i += 1) {
                var x = fallingObject.getBody[i].coordinate.x;
                var y = fallingObject.getBody[i].coordinate.y;

                if (earth.isInRange(x, y) && earth.contains(x, y)) {
                    collisions[tetris.CollisionType.Earth] = tetris.CollisionType.Earth;
                    continue;
                }

                if (x < 0) {
                    collisions[tetris.CollisionType.LeftEdge] = tetris.CollisionType.LeftEdge;
                }
                if (x >= earth.width) {
                    collisions[tetris.CollisionType.RightEdge] = tetris.CollisionType.RightEdge;
                }
                if (y < 0) {
                    collisions[tetris.CollisionType.TopEdge] = tetris.CollisionType.TopEdge;
                }
                if (y >= earth.height) {
                    collisions[tetris.CollisionType.Earth] = tetris.CollisionType.Earth;
                }
            }

            return collisions;
        },
    };

    tetris.CollisionDetector = CollisionDetector;
})();